package comm;

import java.io.Serializable;

/**
 * Messages sent from the server to clients. A message contains a type (enum), 
 * and a sender (String). 
 * <p>
 * <b>Important:</b> <br>
 * A <i>message</i> refers to an object sent from the server to a client.<br>
 * A <i>Moodish message</i> refers to an object sent from a client to his or her friends<br>
 * 
 * <p>
 * When a Moodish message is being sent from one user to his/her friends, the sender
 * is the nickname of the client. For all other messages the sender's nickname should be {@link #SERVER}. 
 * <p>
 * 
 * 
 * @author alc
 * @version 1 
 */

public class ClientMessage implements ClientSideMessage, Serializable{
	private static final long serialVersionUID = 1098195703262351085L;
	private Type message_type;
	private String message_sender;
	private String message_payload;

	/**
	 * Constructor that creates an object that represents:
	 *  
	 * A <i>Moodish message</i> refers to an object sent from a client to his or her friends<br>
	 * 
	 * @param m_sender			the user that sent the message
	 * @param m_payload			the content of the message	
	 * @param m_type			the type of the message (expect MoodishMessage)
	 */
	public ClientMessage(String m_sender, String m_payload , Type m_type){
		this.message_sender = m_sender;
		this.message_payload = m_payload;
		this.message_type = m_type;
	}
	/**
	 * A <i>message</i> refers to an object sent from the server to a client.<br>
	 * 
	 * @param m_payload				the content of the message
	 * @param m_type				the type of the message (expects any type expect Moodish)
	 */
	public ClientMessage( String m_payload , Type m_type){
		this.message_sender = ClientSideMessage.SERVER;
		this.message_payload = m_payload;
		this.message_type = m_type;
	}
	/**
	 * Gets the type of the message.
	 * 
	 * @return type of the message.
	 */
	@Override
	public Type getType() {
		return this.message_type;
	}
	/**
	 * Gets the sender of the message. The sender is the nickname of the message sender in case the message sent is 
	 * a Moodsih message from one client to another. For all other messages. The sender will be {@link #SERVER}
	 * 
	 * @return nickname of the sender.
	 */
	@Override
	public String getSendersNickname() {
		return this.message_sender;
	}
	/**
	 * Gets the payload of the message.
	 * 
	 * @return payload.
	 */
	@Override
	public String getPayload() {
		return this.message_payload;
	}
}
